// src/database/database.module.ts
import { Module, OnModuleInit } from '@nestjs/common';
import { DataSource } from 'typeorm';
import { Permission } from '@src/permission/entity/permission.entity';
import { runSeeds } from './seed';

@Module({})
export class DatabaseModule implements OnModuleInit {
  constructor(private readonly dataSource: DataSource) {}

  async onModuleInit(): Promise<void> {
    const permissionRepo = this.dataSource.getRepository(Permission);
    const count = await permissionRepo.count();
    if (count === 0) {
      await runSeeds(this.dataSource);
    }
  }
}
